// pages/me/me.js
const app = getApp();
Page({
  // 页面的初始数据
  data: {
    userInfo: null,
  },
  onShow(options) {
    this.setData({
      userInfo: wx.getStorageSync('user')
    })
  },
  // button获取用户信息
  onGotUserInfo: function (e) {
    wx.getUserProfile({
      desc: '用于完善会员资料', 
      success: (res) => {
        console.log(res)
        if (res.userInfo) {
          var user = res.userInfo;
          this.setData({
            userInfo: res.userInfo,
          })
          app.globalData.userInfo.nickName = user.nickName;
          app.globalData.userInfo.avatarUrl = user.avatarUrl;
          app._saveUserInfo(app.globalData.userInfo);
        } else {
        wx.showToast({
          title: '授权失败',
        })
        }
      }
    })
  },
   //前往个人信息
   navToinfo() {
    wx.navigateTo({
      url: '/pages/info/info',
    })
  },
 
  //去我的发布页
 navTomyOrder() {
    wx.navigateTo({
      url: '/pages/myorder/myorder',
    })
  },
  //去我的抢单页
  navTomyService() {
    wx.navigateTo({
      url: '/pages/myservice/myservice',
    })
  },
  navTomyMoney(){
    wx.navigateTo({
      url: '/pages/mymoney/mymoney',
    })
  },
  //退出登录
 loginOut() {
    wx.setStorageSync('user', null)
    this.setData({
      userInfo: null,
    })
  },
})